<template>
  <div>
    <van-nav-bar
      title="选择城市"
      left-arrow
      @click-left="onClickLeft"
      class="head"
    >
    </van-nav-bar>
    <van-search v-model="value" shape="round" placeholder="搜索城市名称" />
    <div></div>
    <div class="location">
      <h2>定位城市</h2>
      <ul>
        <li>杭州市</li>
      </ul>
    </div>
    <div class="hot">
      <h2>热门城市</h2>
      <ul>
        <li v-for="item in cityList" :key="item.cityId" @click="onClickLeft">
          {{ item.name }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from "vue";
import { NavBar, Search } from "vant";
import { useRouter } from "vue-router";
export default {
  components: {
    VanNavBar: NavBar,
    VanSearch: Search,
  },
  setup() {
    const router = useRouter();
    const value = ref("");
    const cityList = ref({});
    onMounted(async () => {
      const data = await fetch("http://www.pudge.wang:3080/api/area/list").then(
        (rsp) => rsp.json()
      );
      cityList.value = data.result[0].cities;
    });
    const onClickLeft = () => {
      router.go(-1);
    };
    return { onClickLeft, value, cityList };
  },
};
</script>

<style lang="less" scoped>
.hot,
.location {
  margin-top: 27px;
  > h2 {
    margin-left: 15px;
    width: 69px;
    height: 11px;
    font-size: 12px;
    font-family: PingFang;
    font-weight: 500;
    color: #666666;
    line-height: 18px;
    margin-bottom: 10px;
  }
  > ul {
    display: flex;
    flex-wrap: wrap;
    li {
      text-align: center;
      width: 100px;
      height: 27px;
      background: #ffffff;
      border-radius: 14px;
      font-size: 14px;
      font-family: PingFang;
      font-weight: 500;
      color: #333333;
      line-height: 27px;
      margin-left: 18px;
      margin-top: 10px;
    }
  }
}
.location {
  > ul {
    > li {
      margin-left: 18px;
    }
  }
}
</style>
